/*******************************************************************************
 * @file fdt_daemon.h
 * @brief  inter process Fast Data Transfer
 *
 *
 * Author: Kevinx
 *
 * Copyright (c) 2015 Kevinx. All Rights Reserved.
 *
 * CONFIDENTIALITY AND LIMITED USE
 *
 * This software, including any software of third parties embodied herein,
 * contains information and concepts which are confidential to Kevinx
 * and such third parties. This software is licensed for use
 * solely in accordance with the terms and conditions of the applicable
 * license agreement with Kevinx or its authorized distributor.
 ************************************************************************************/
#ifndef __FDT_DAEMON_H__
#define __FDT_DAEMON_H__
#include "fdt_channel.h"
#include "fdt_net.h"

struct fdt_fdesc {
    int fd;
    void (*action)(int fd, void*);
    void* private_data;

    struct list_head list;
};

struct fdt_daemon {

    struct {
        int maxfd;
        int nr_fd;
        fd_set rset;
    } sop;

    struct list_head list;
    int nr_ch;

    struct list_head fd_list;
    int nr_fd;

    struct list_head sock_list;
    int nr_sock;    
};

#define fdt_set_fddata(p, _fd, func, data) \
    do { \
        (p)->fd = (_fd); \
        (p)->action = func; \
        (p)->list.prev = NULL; \
        (p)->list.next = NULL; \
        (p)->private_data = (data); \
    } while (0)

/*
 * fdt_daemon_init
 *  init fdt_daemon struct
 *
 */
void fdt_daemon_init(struct fdt_daemon* dm);

void fdt_daemon_add_channel(struct fdt_daemon* dm, struct fdt_channel* c, struct fdt_callback* cb);

void fdt_daemon_del_channel(struct fdt_daemon* dm, struct fdt_channel* c);

void fdt_daemon_add_fdesc(struct fdt_daemon* dm, struct fdt_fdesc* fdesc);

void fdt_daemon_del_fdesc(struct fdt_daemon* dm, struct fdt_fdesc* fdesc);

void fdt_daemon_add_socket(struct fdt_daemon* dm, struct fdt_socket* sock, struct fdt_sock_cb* cb);

void fdt_daemon_del_socket(struct fdt_daemon* dm, struct fdt_socket* sock);

int fdt_daemon_start(struct fdt_daemon* dm);


#endif /* __FDT_DAEMON_H__ */
